package com.cheyunkeji.er.view.evaluate;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.view.AbsDialog;


/**
 * Created by Michael on 2017/3/30 14:24.
 */

public class ImageSelectDialog extends AbsDialog implements View.OnClickListener {

    private static final String TAG = ImageSelectDialog.class.getSimpleName() ;
    private Context context;
    private TextView tvCamera , tvGallery ,tvTitle ;
    private TextView tvCancel;
    private String titleStr ;
    private RelativeLayout rlGallery , rlTakePhoto ;

    /**
     *是否点击则取消，默认为true
     */
    private boolean clickCancelable = true ;

    private ImageSelectListener listener;


    public ImageSelectDialog(Context context, ImageSelectListener listener ,String titleStr ) {
        super(context, R.style.dialog_style_dim_3);
        this.context = context;
        this.listener = listener;
        this.titleStr = titleStr ;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.er_img_select_dialog);
        findViews();
        setListener();
    }


    private void findViews() {
        init();
        tvTitle = (TextView) findViewById(R.id.dialog_title);
        tvCamera = (TextView) findViewById(R.id.tv_camera);
        tvGallery = (TextView) findViewById(R.id.tv_gallery);
        tvCancel = (TextView) findViewById(R.id.tv_cancel);
        rlGallery = (RelativeLayout) findViewById(R.id.rl_gallery);
        rlTakePhoto = (RelativeLayout) findViewById(R.id.rl_take_photo);

        if(!TextUtils.isEmpty(titleStr)){
            tvTitle.setText(titleStr);
        }else{
            tvTitle.setVisibility(View.GONE);
        }

    }

    public void setTitleStr(String titleStr){
        this.titleStr = titleStr ;
        tvTitle.setText(titleStr);
    }

    private void setListener() {
        tvCancel.setOnClickListener(this);
        rlGallery.setOnClickListener(this);
        rlTakePhoto.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {

        if(clickCancelable) dismiss();

        switch (v.getId()) {

            case R.id.rl_take_photo:
                listener.onTakePhotoWithSystemCamera();
                break;

            case R.id.rl_gallery:
                listener.onSelectImgOnGallery();
                break;

            default:
                break;
        }
    }

    /**
     * 系统相机、图库点击回调接口
     */
    public interface ImageSelectListener {

         void onTakePhotoWithSystemCamera();

         void onSelectImgOnGallery();
    }
}
